from itsdangerous import  TimedJSONWebSignatureSerializer as Serializer

from apps.oauth.constants import OPENID_TOKEN_EXPIRES_TIME
from meiduo_mall import settings
from itsdangerous import SignatureExpired,BadData
import logging
logger = logging.getLogger('django')



def generic_openid_token(openid):
    s=Serializer(secret_key=settings.SECRET_KEY,expires_in=OPENID_TOKEN_EXPIRES_TIME)
    data={
        'openid':openid
    }
    token=s.dumps(data)

    return token.decode()
def check_openid_token(token):
    s = Serializer(secret_key=settings.SECRET_KEY, expires_in=OPENID_TOKEN_EXPIRES_TIME)
    try:
        result = s.loads(token)

    except BadData as e:
        logger.error(e)
        return None

    return result.get('openid')
